<template>
	<view class="page">
		<u-navbar :isBack="true" :title="toptitle" title-color="#101010" 
		:background="{background: '#fff'}" :borderBottom="false"></u-navbar>
		
		
		<view style="padding: 32rpx 24rpx;">
			<view style="padding: 32rpx 24rpx;background: #fff;border-radius: 24rpx;">
				<view style="display: flex;align-items: center;justify-content: space-between;
				font-size: 32rpx;">
					<view style="flex: 1;color: #333333;">头像</view>
					<view style="display: flex;align-items: center;" @click="changeAvatar">
						<image :src="userinfo.avatar" mode="aspectFill" style="width: 64rpx;height: 64rpx;border-radius: 50%;"></image>
					</view>
				</view>
				<view style="display: flex;align-items: center;margin-top: 50rpx;justify-content: space-between;
				font-size: 32rpx;" @click="nicknameShow = true">
					<view style="flex: 1;color: #333333;">姓名</view>
					<view style="display: flex;align-items: center;">
						<view style="color: #999999;margin-right: 8rpx;">{{userinfo.nickname}}</view>
						<image src="@/static/my/ri.png" mode="widthFix" style="width: 32rpx;"></image>
					</view>
				</view>
				<view style="display: flex;align-items: center;margin-top: 50rpx;justify-content: space-between;
				font-size: 32rpx;" @click="phoneShow = true">
					<view style="flex: 1;color: #333333;">个人备注</view>
					<view style="display: flex;align-items: center;">
						<view style="color: #999999;margin-right: 8rpx;">{{userinfo.mobile}}</view>
						<image src="@/static/my/ri.png" mode="widthFix" style="width: 32rpx;"></image>
					</view>
				</view>
			</view>
		</view>
		
		<!-- <view style="position: fixed;bottom: 60rpx;width: 100%;">
			<image src="../../static/bottomimg.png" mode="widthFix" style="width: 100%;"></image>
		</view> -->
		<u-toast ref="uToast" />
		
		<!-- 真实姓名弹窗 -->
		<u-modal v-model="nicknameShow" title="姓名" :show-cancel-button="true" confirm-text="确认"
		@confirm="profileUserInfo('nickname')">
			<view class="slot-content">
				<view style="padding: 48rpx 32rpx 64rpx 32rpx;">
					<view style="font-size: 28rpx;color: #666B75;">真实姓名</view>
					<view style="flex: 1;background: #F5F5F5;padding: 24rpx;border-radius: 16rpx;margin-top: 8rpx;">
						<input type="text" placeholder="请填写您的真实姓名" v-model="userinfo.nickname">
					</view>
				</view>
			</view>
		</u-modal>
		
		<!-- 备注弹窗 -->
		<u-modal v-model="phoneShow" title="备注" :show-cancel-button="true" confirm-text="确认"
		@confirm="profileUserInfo('bio')">
			<view class="slot-content">
				<view style="padding: 48rpx 32rpx 64rpx 32rpx;">
					<view style="font-size: 28rpx;color: #666B75;">个人备注</view>
					<view style="flex: 1;background: #F5F5F5;padding: 24rpx;border-radius: 16rpx;margin-top: 8rpx;">
						<input type="text" placeholder="请填写您的备注信息" v-model="userinfo.nickname">
					</view>
				</view>
			</view>
		</u-modal>
		
	</view>
</template>

<script>
	import appurl_config from 'utils/config.js'
	import {request} from 'utils/request.js'
	import Vue from 'vue'
	var moment = require('moment');
	export default {
		data() {
			return {
				type: '',
				toptitle: '',
				nicknameShow: false,
				phoneShow: false,
				
				topImage: appurl_config.appurlImg + '/app/my/topbg.png',
				isLogin: false,
				
				meetList: [],
				date:'',
				showCancelConfirm:false,
				showOverConfirm:false,
				id:'',
				
				beingNum:0,
				waitNum:0,
				orList:[],
				state:1,
				
				userinfo: {},
			}
		},
		onLoad(e) {
			console.log(e)
			if(e.type){
				this.type = e.type;
				if(e.type == "info"){
					this.toptitle = '个人资料';
					this.userInfoData();
				}else{
					this.toptitle = '账号绑定';
				}
			}
			// this.login();
			// // 告诉页面需要刷新登录状态
			// uni.$on('htmlRefresh', (e) => {
			// 	console.log('子页面---->>>>>>', e);
			// 	this.login();
			// })
			uni.hideShareMenu();
		},
		onShow(){
			// if(Vue.prototype.Token){
			// 	this.$nextTick(()=>{
			// 		this.$refs.dateTable.show(this.vuex_user.department == '律师')
			// 		this.getMeetList()
			// 	})
			// }
		},
		methods: {
			userInfoData(){
				request.getWithToken({
					url: '/user/userInfo'
				}).then(res=>{
					console.log('返回用户信息：', res);
					if(res.code == 1){
						this.userinfo = res.data.user;
					}
				})
			},
			// 修改信息
			profileUserInfo(e){
				let getData = {};
				if(e == 'nickname'){
					getData.nickname = this.userinfo.nickname;
				}
				if(e == 'avatar'){
					getData.avatar = this.userinfo.avatar;
				}
				if(e == 'bio'){
					getData.bio = this.userinfo.bio;
				}
				request.postWithToken({
					url: '/user/profile',
					data: getData
				}).then(res=>{
					this.nicknameShow = false;
					this.userInfoData();
				})
			},
			// 修改头像
			changeAvatar() {
			    let that = this;
				let userToken = uni.getStorageSync('userToken');
			    uni.chooseImage({
			        count: 1,
			        sizeType: ['compressed'],
			        sourceType: ['album','camera'],
			        success: (chooseImageRes) => {
			            uni.uploadFile({
			                url: appurl_config.appurl + '/common/upload', //请求地址
			                filePath: chooseImageRes.tempFilePaths[0],
			                name: "file",
			                header: {
			                    // 设置请求的 header
			                    token: userToken,
			                },
			                success: (res) => {
			                    that.userinfo.avatar = JSON.parse(res.data).data.fullurl;
								that.profileUserInfo('avatar');
			                },
			                fail: (err) => {
			                    uni.showToast({
			                        title: err.msg,
			                        icon: 'none'
			                    })
			                    console.log('uploadFile_err: ', err);
			                },
			            });
			        }
			    });
			},
			jumpTo(path){
				uni.navigateTo({
					url: path
				})
			},
			toDetail(item){
				Vue.prototype.MeetInfo = item
				uni.navigateTo({
					url:'detail'
				})
			},
		}
	}
</script>

<style>
	page{
		background-color: #F7F7F7 !important;
	}
</style>
<style lang="scss" scoped>
	.top-box{
		background-size: 100% 100%;
	}
</style>
